package com.xiaoge.system.service.impl;

import com.xiaoge.system.entity.Login;
import com.xiaoge.system.mapper.LoginMapper;
import com.xiaoge.system.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    public LoginMapper loginMapper;
    @Autowired
    public PasswordEncoder passwordEncoder;
    @Override
    public String queryIsHaveUser(String userName, String password) {
        Login list = loginMapper.queryIsHaveUser(userName);
        if (list == null ){
            return "";
        }
        String db_salt = (String) list.getSalt();
        String db_password = (String) list.getPassword();
        boolean matches = passwordEncoder.matches(password, db_password);
        if (matches){
            return list.getId();
        }
        return "";
    }
}
